package com.mspbots.web.security;

import com.mspbots.api.page.Page;
import com.mspbots.web.security.service.UsersService;
import lombok.RequiredArgsConstructor;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * com.mspbots.web.security.UserController
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/9/4
 */
@RestController
@RequestMapping("users")
@RequiredArgsConstructor
public class UsersController {

    private final UsersService usersService;

    @GetMapping("page")
    public Mono select(User user, Page<User> pageable) {
        return this.usersService.loadAllPage(user, pageable);
    }

    @GetMapping("all")
    public Flux loadAll(User user) {
        return this.usersService.loadAll(user);
    }

    @GetMapping("info")
    public Mono<User> getOne(@RequestParam String username) {
        return this.usersService.loadUser(username);
    }

    @PutMapping("save")
    public Mono<User> put(@RequestBody User user) {
        return this.usersService.save(user);
    }

    @GetMapping("authList")
    public Flux authList(Integer tenantId) {
        Assert.notNull(tenantId, "Request tenantId is not null");
        return this.usersService.authList(tenantId);
    }
}
